export enum TypePickerOptionEnum {
  'all' = -1,
  'warn' = 1,
  'fault' = 2,
  'noti' = 0,
}


// 比较两个列表是否相等
function compareList({ a, b, isSame }: { a: any[], b: any[], isSame: (a1: any, b1: any) => boolean }) {
  if (a.length !== b.length) return true;
  for (let i = 0; i < a.length; i++) {
    if (!isSame(a[i], b[i])) return true;
  }
  return false;
}

// 是不是一样的分享消息数据
const isSameShare = (a, b) => {
  const {
    share: { id: aId, read: aRead, handle: aHandle },
  } = a;
  const {
    share: { id: bId, read: bRead, handle: bHandle },
  } = b;
  return aId === bId && aRead === bRead && aHandle === bHandle;
};

// 获取消息列表的未读消息数
const unreadCount = (data: any[]) => {
  if (data && data.length > 0) {
    const arr = data.filter(i => i.read === false);
    return arr.length;
  }
  return 0;
};

// 是不是一样的设备消息数据
const isSameMessageDevice = (a, b) => {
  const {
    device: { sno: aSno },
    content: aContent,
  } = a;
  const { ctime: aCtime, type: aType, read: aRead, consumer: aConsumer, msgType: aMsgType } = aContent[0];
  const {
    device: { sno: bSno },
    content: bContent,
  } = b;
  const { ctime: bCtime, type: bType, read: bRead, consumer: bConsumer, msgType: bMsgType } = bContent[0];
  return (
    aSno === bSno &&
    aType === bType &&
    aRead === bRead &&
    aConsumer === bConsumer &&
    aMsgType === bMsgType &&
    unreadCount(aContent) === unreadCount(bContent) &&
    aCtime.format('YYYY/MM/DD HH:mm') === bCtime.format('YYYY/MM/DD HH:mm')
  );
};

// 比较两个设备消息列表是否一致
const compareDeviceMessageList = (a, b) => {
  const res = compareList({ a, b, isSame: isSameMessageDevice });
  console.log('compareDeviceMessageList', res);
  return res;
};

// 比较两个分享消息列表是否一致
const compareShareMessageList = (a, b) => {
  const res = compareList({ a, b, isSame: isSameShare });
  console.log('compareShareMessageList', res);
  return res;
};



export { compareList, isSameShare, unreadCount, isSameMessageDevice, compareDeviceMessageList, compareShareMessageList }
